import java.util.Arrays;
import java.util.Scanner;


public class Main1212 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n= sc.nextInt();
        int[] arr=new int[n];
        for (int i=0;i<n;i++){
            arr[i]= sc.nextInt();
        }
        int max =arr[n-1];
        int min =arr[0];
        int a=arr[n-1];
        int a1=n-1;
        int b=arr[0];
        int b1=0;
        for (int i=0;i<arr.length;i++){
            if (arr[i]>max){
                max=arr[i];
                b1=i;
            }
            if (arr[i]<min){
                min=arr[i];
                a1=i;
            }
        }
        if (arr[n-1]!=max&&arr[0]!=min){
            arr[0]=min;
            arr[a1]=b;
            arr[n-1]=max;
            arr[b1]=a;
        }
        for (int i=0;i<n;i++){
            System.out.print(arr[i]+" ");
        }
    }
}
